package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiDatabaseScriptConfigBo;
import com.cw.jeeyt.dao.model.api.ApiDatabaseScriptConfigDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 数据库脚本导出配置转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiDatabaseScriptConfigConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiDatabaseScriptConfigBo do2Bo(ApiDatabaseScriptConfigDo model) {
        if (model == null) {
            return null;
        }
        ApiDatabaseScriptConfigBo bo = new ApiDatabaseScriptConfigBo();
        bo.setId(model.getId());
        bo.setDatabaseId(model.getDatabaseId());
        bo.setAuthor(model.getAuthor());
        bo.setTableSpace(model.getTableSpace());
        bo.setIndexSpace(model.getIndexSpace());
        bo.setDatabaseOwner(model.getDatabaseOwner());
        bo.setExportDate(model.getExportDate());
        bo.setExportScriptKind(model.getExportScriptKind());
        bo.setScriptVarSet(model.getScriptVarSet());
        bo.setScriptVersion(model.getScriptVersion());
        bo.setTablePrefix(model.getTablePrefix());
        bo.setExportComment(model.getExportComment());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiDatabaseScriptConfigDo bo2Do(ApiDatabaseScriptConfigBo bo) {
        if (bo == null) {
            return null;
        }
        ApiDatabaseScriptConfigDo model = new ApiDatabaseScriptConfigDo();
        model.setId(bo.getId());
        model.setDatabaseId(bo.getDatabaseId());
        model.setTableSpace(bo.getTableSpace());
        model.setIndexSpace(bo.getIndexSpace());
        model.setDatabaseOwner(bo.getDatabaseOwner());
        model.setAuthor(bo.getAuthor());
        model.setExportDate(bo.getExportDate());
        model.setExportScriptKind(bo.getExportScriptKind());
        model.setScriptVarSet(bo.getScriptVarSet());
        model.setScriptVersion(bo.getScriptVersion());
        model.setTablePrefix(bo.getTablePrefix());
        model.setExportComment(bo.getExportComment());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiDatabaseScriptConfigBo> doList2BoList(List<ApiDatabaseScriptConfigDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiDatabaseScriptConfigConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiDatabaseScriptConfigDo> boList2DoList(List<ApiDatabaseScriptConfigBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiDatabaseScriptConfigConverter::bo2Do));
    }
}